﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Template;
using System.Xml.Serialization;
using System.IO;
using Entity;
using System.Reflection;
using NetworkHandler;

namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 序列化
        /// </summary>
        /// <param name="filePath"></param>
        public void Serialiaze(String filePath)
        {
            List<TemplateXML> list = new List<TemplateXML>();
            TemplateXML temp = new TemplateXML() { Title = "1", URL = "2", Regex = "4" };
            list.Add(temp);
            TemplateXML c = new TemplateXML()
            {
                Title = "Technology_Report",
                Regex="",
                URL = "http://www.51voa.com/Technology_Report_#@#.html",
                ChildTemplate = list,
                Result=new Data(){Text="text",Mp3Url="url",LRC="lrc",Time=DateTime.Now},
            };
            XmlSerializer xs = new XmlSerializer(typeof(TemplateXML));
            Stream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
            xs.Serialize(stream, c);
            stream.Close();
        }
        /// <summary>
        /// 反序列化
        /// </summary>
        /// <param name="filePath"></param>
        public void Deserialize(String filePath)
        {
            XmlSerializer xs = new XmlSerializer(typeof(TemplateXML));
            Stream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            TemplateXML p = (TemplateXML)xs.Deserialize(stream);
            stream.Close();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Download.DownloadFile(@"http://www.51voa.com/Technology_Report_1.html", "C:\\a.html", () => { MessageBox.Show("download completed!"); });
            //int a = 88;
            //string b = ((char)a).ToString();
            //MessageBox.Show(b);
            //Serialiaze("C:\\a.xml");
            //Deserialize("Template\\SVOA_Technology.xml");
            //StringHandler sh = new StringHandler();
            //sh.GetType().InvokeMember("DoSome", BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod, null, null, null);
        }
    }
}
